# \author  Neil Turton <neilt@amd.com>
#  \brief  Nanotube front-end
#   \date  2020-06-10
#
###########################################################################
# Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT
###########################################################################

Import('env capture_output')

llvm_config = env.get('LLVM_CONFIG')
if llvm_config == None:
    Return("")

env.Append(CXXFLAGS=env['LLVM_CXX_FLAGS'].split(" "))
env.Append(LINKFLAGS=env['LLVM_LD_FLAGS'].split(" "))
env.Append(LIBPATH=[env['BUILD_DIR']])
env.Append(RPATH=[env['LLVM_LIB_DIR']])
env.Append(RPATH=[env['BUILD_DIR'].abspath])

sources = [
    'Convert_EBPF.cpp',
]

lib_nanotube_env = env.Clone()
lib_nanotube_env.Append(CPPPATH=[
    ".",
    "../include",
    "../back_end",
])
lib_nanotube_env.SharedLibrary('ebpf_passes', sources)

prog_libs = capture_output([
    llvm_config, '--libs',
    'Core',
    'Support',
])

prog_env = env.Clone()
prog_env.Append(CPPPATH=["."])
prog_env.Append(LIBS=['elf'])
prog_env.Append(LIBS=prog_libs.split(" "))
prog_env.Program('${BUILD_TOP}/bpf-compile',
                 ['nanotube-ebpf.cc'])
